package com.sqsf.service.impl;

import com.sqsf.dao.AccountDao;
import com.sqsf.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


@Service("accountService")
@Transactional
public class AccountServiceImpl implements AccountService {
    @Autowired
    private AccountDao accountDao;

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    @Transactional(isolation= Isolation.DEFAULT,propagation = Propagation.REQUIRED,timeout = -1,readOnly = false)
    @Override
    public void zz(String out, String in, double money) {
        accountDao.updateSubMoneyByName(out, money); // 扣款

        // 模拟业务异常（如余额不足、网络错误等）
        if (money < 0) {
            throw new RuntimeException("转账金额不能为负数");
        }

        accountDao.updateAddMoneyByName(in, money); // 加款
    }
}
